{extend name='common/_container'}
{block name="content"}
<div class="ibox float-e-margins">
	<div class="ibox-content layui-form">
		<div class="form-horizontal" id="CodeInfoForm">
			<div class="row">
				<div class="col-sm-7">
				<!-- form start -->
					<div class="form-group">
						<label class="col-sm-2 control-label">首页模板：</label>
						<div class="col-sm-3">
							<input type="text" id="index_tpl" value="index" name="index_tpl" class="form-control" placeholder="请输入内容模板">
						</div>
						<div class="col-sm-3" style="margin-left:-30px;">
							<select lay-ignore id="tplSelect" class="form-control" target="#index_tpl">
								<option value="">请选择</option>
								{foreach name="tpList" id="vo"}
								<option value="{$vo.name}">{$vo.file}</option>
								{/foreach}								
							</select>
						</div>
					</div>
					
				<!-- form end -->
				</div>
			</div>
			<div class="row btn-group-m-t">
				<div class="col-sm-9">
					<button type="button" class="btn btn-primary" onclick="CodeInfoDlg.doIndex()" id="ensure">
						<i class="fa fa-check"></i>&nbsp;生成首页
					</button>
				</div>
			</div>
			<div class="hr-line-dashed"></div>
			<div class="row" style="margin-top:20px;">
				<div class="col-sm-7">
				<!-- form start -->
					<div class="form-group">
						<label class="col-sm-2 control-label">请选择栏目：</label>
						<div class="col-sm-6">
							<select lay-ignore class="form-control" id="list_class_id">
								<option value="">请选择栏目</option>
								{sql query="select class_id,class_name,pid from pre_catagory"}
								<option value="{$sql.class_id}">{$sql.class_name}</option>
								{/sql}
							</select>
							<span class="help-block m-b-none">默认不选择则更新全部栏目</span>
						</div>
					</div>
					
				<!-- form end -->
				</div>
			</div>
			<div class="row btn-group-m-t">
				<div class="col-sm-9">
					<button type="button" class="btn btn-primary" onclick="CodeInfoDlg.doList()" id="ensure">
						<i class="fa fa-check"></i>&nbsp;生成列表页
					</button>
				</div>
			</div>
			<div class="hr-line-dashed"></div>
			<div class="row" style="margin-top:20px;">
				<div class="col-sm-7">
				<!-- form start -->
					<div class="form-group">
						<label class="col-sm-2 control-label">请选择栏目：</label>
						<div class="col-sm-6">
							<select lay-ignore class="form-control" id="view_class_id">
								<option value="">请选择栏目</option>
								{sql query="select class_id,class_name,pid from pre_catagory"}
								<option value="{$sql.class_id}">{$sql.class_name}</option>
								{/sql}
							</select>
							<span class="help-block m-b-none">默认不选择则更新全部栏目</span>
						</div>
					</div>
					
					<div class="form-group">
						<label class="col-sm-2 control-label">起始ID：</label>
						<div class="col-sm-6">
							<input type="text" id="startId"  name="startId" class="form-control" placeholder="请输入起始ID">
						</div>
					</div>
					
					
					<div class="form-group">
						<label class="col-sm-2 control-label">结束ID：</label>
						<div class="col-sm-6">
							<input type="text" id="endId"  name="endId" class="form-control" placeholder="请输入结束ID">
						</div>
					</div>
					
					<div class="form-group">
						<label class="col-sm-2 control-label">每次更新条数：</label>
						<div class="col-sm-6">
							<input type="text" id="pagesize"  name="pagesize" value="20" class="form-control" placeholder="每页更新条数">
						</div>
					</div>
				<!-- form end -->
				</div>
			</div>
			<div class="row btn-group-m-t">
				<div class="col-sm-9">
					<button type="button" class="btn btn-primary" onclick="CodeInfoDlg.doView()" id="ensure">
						<i class="fa fa-check"></i>&nbsp;生成详情页
					</button>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
$(function(){
	$("#tplSelect").change(function(){
		pick = $(this).attr('target');
		var val = $(this).find('option:selected').val();
		$(pick).val(val);
	});
})

var CodeInfoDlg = {
	CodeInfoData: {},
	validateFields: {
		index_tpl: {
			validators: {
				notEmpty: {
					message: '首页模板不能为空'
	 			},
	 		}
	 	},
	 }
}

CodeInfoDlg.collectData = function () {
	this.set('index_tpl').set('list_class_id').set('view_class_id').set('startId').set('endId').set('pagesize');
};


CodeInfoDlg.doIndex = function () {
	 this.clearData();
	 this.collectData();
	 if (!this.validate()) {
	 	return;
	 }
	 var ajax = new $ax(Feng.ctxPath + "/Cms.DoHtml/doIndex", function (data) {
	 	if ('00' === data.status) {
	 		Feng.success(data.msg);
	 		window.parent.CodeGoods.table.refresh();
	 		CodeInfoDlg.close();
	 	} else {
	 		Feng.error(data.msg + "！");
		 }
	 }, function (data) {
	 	Feng.error("操作失败!" + data.responseJSON.message + "!");
	 });
	 ajax.set(this.CodeInfoData);
	 ajax.start();
};

CodeInfoDlg.doList = function () {
	var list_class_id = $("#list_class_id option:selected").val();
	var index = layer.open({type: 2,title: '开始生成',area: ['500px', '300px'],fix: false, maxmin: true,content: Feng.ctxPath + '/Cms.DoHtml/doList/classId/'+list_class_id});
	this.layerIndex = index;
}


CodeInfoDlg.doView = function () {
	var view_class_id = $("#view_class_id option:selected").val();
	var pagesize = $("#pagesize").val();
	var startId = $("#startId").val();
	var endId = $("#startId").val();
	var index = layer.open({type: 2,title: '开始生成',area: ['500px', '300px'],fix: false, maxmin: true,content: Feng.ctxPath + '/Cms.DoHtml/doView?classId='+view_class_id+'&pagesize='+pagesize+'&startId='+startId+'&endId='+endId});
	this.layerIndex = index;
}


</script>
<script src="__PUBLIC__/static/js/base.js" charset="utf-8"></script>

{/block}
